﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;

namespace IPR_TrainExamSys_TY.Search
{
    public partial class FrmScoreSearch : Form
    {
        public FrmScoreSearch()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            superGridControl1.PrimaryGrid.DataSource = null;
            string sql = "select ksls,gh,xm,ksjg,kssj,a.paperBh,c.paperName,WorkShop,ClassGroup,Job,ExamAddr,a.GWHGZSBH," +
                " LocomotiveNo,Sex,Nation,Native,PoliticalStatus,NL,JB from pe_llksjg a "+
                " left join T_PublicEmployee b on a.GWHGZSBH=b.GWHGZSBH and a.gh=b.EmployeeId " +
                " left join pe_paperMa c on a.paperBh=c.paperBh "+
                " where 1=1 ";
                if(cmbPaperName.SelectedValue!=null)
                    sql+=" and a.paperBh='"+cmbPaperName.SelectedValue.ToString()+"' ";
            if(tbEmployeeId.Text.Trim()!="")
                 sql +="and gh='"+tbEmployeeId.Text.Trim()+"' ";
            if (tbEmployeeName.Text.Trim() != "")
                sql += " and xm like '%" + tbEmployeeName.Text.Trim() + "%'";
            sql += " order by a.id ";
            try
            {
                DataSet ds = new T_Public().Query(sql);
                if(ds!=null)
                    if(ds.Tables.Count>0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            superGridControl1.PrimaryGrid.DataSource = ds.Tables[0];
                        }
            }
            catch (Exception exc)
            {

            }
        }

        private void FrmScoreSearch_Load(object sender, EventArgs e)
        {
            getPaperName();
        }

        private void getPaperName()
        {
            try
            {
                string sOrder = " id desc ";
                DataSet ds = new pe_paperMa().GetList(0,"",sOrder);
                if(ds!=null)
                    if(ds.Tables.Count>0)
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            cmbPaperName.DataSource = ds.Tables[0];
                            cmbPaperName.DisplayMember = "paperName";
                            cmbPaperName.ValueMember = "paperBh";
                            cmbPaperName.SelectedIndex = 0;
                        }
            }
            catch (Exception exc)
            {
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        
        private void superGridControl1_CellDoubleClick(object sender, DevComponents.DotNetBar.SuperGrid.GridCellDoubleClickEventArgs e)
        {

            if (cmbPaperName.SelectedValue == null) return;
            string spaperid = cmbPaperName.SelectedValue.ToString();
            string spapername = cmbPaperName.Text.ToString();
            string semployeeid = "";
            string semployeename = "";
            string sexamaddr = "";
            string sexamsj = "";
            string stotalcj = "";
            try
            {
                semployeeid = e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value != null ? e.GridPanel.GetCell(e.GridCell.RowIndex, 0).Value.ToString() : "";
                semployeename = e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value != null ? e.GridPanel.GetCell(e.GridCell.RowIndex, 1).Value.ToString() : "";
                sexamsj = e.GridPanel.GetCell(e.GridCell.RowIndex, 7).Value != null ? e.GridPanel.GetCell(e.GridCell.RowIndex, 7).Value.ToString() : "";
                sexamaddr = e.GridPanel.GetCell(e.GridCell.RowIndex, 8).Value != null ? e.GridPanel.GetCell(e.GridCell.RowIndex, 8).Value.ToString() : "";
                stotalcj = e.GridPanel.GetCell(e.GridCell.RowIndex, 9).Value != null ? e.GridPanel.GetCell(e.GridCell.RowIndex, 9).Value.ToString() : "";
                string ksls = e.GridPanel.GetCell(e.GridCell.RowIndex, 10).Value != null ? e.GridPanel.GetCell(e.GridCell.RowIndex, 10).Value.ToString() : "";

                string swhere = " ksls='"+ksls+"' ";

                int iR = new pe_llksjginfo().GetRecordCount(swhere);
                if (iR > 0)
                {
                    FrmPaperDetail frmpd = new FrmPaperDetail(semployeeid, semployeename, spaperid, spapername, sexamsj, sexamaddr, stotalcj,ksls);
                    frmpd.ShowDialog();
                    frmpd.Close();
                }
            }
            catch
            {
            }
        }

    }
}
